package com.team.mp.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.team.mp.api.service.intf.ServiceItemsService;
import com.team.mp.mapper.dao.ServiceItemsDao;
import com.team.mp.mapper.entity.ServiceItems;
import com.team.mp.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author lee
* @description 针对表【t_service_items(服务项目)】的数据库操作Service实现
* @createDate 2023-03-27 16:44:20
*/
@Service
public class ServiceItemsServiceImpl implements ServiceItemsService {

    @Resource
    private ServiceItemsDao itemsDao;

    @Override
    public R add(ServiceItems serviceItems) {
        serviceItems.setCreateTime(new Date());
        int insert = itemsDao.insert(serviceItems);
        return insert > 0 ? R.ok() : R.fail("添加失败");
    }

    @Override
    public R deleteById(Integer id) {
        int ret = itemsDao.deleteById(id);
        return ret > 0 ? R.ok() : R.fail("删除失败");
    }

    @Override
    public R updateById(ServiceItems serviceItems) {
        int ret = itemsDao.updateById(serviceItems);
        return ret > 0 ? R.ok() : R.fail("更新失败");
    }

    @Override
    public R queryPage(Integer page, Integer size, Integer itemType, String iname) {
        LambdaQueryWrapper<ServiceItems> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(itemType != null && itemType != 0, ServiceItems::getItemType, itemType)
                .eq(StringUtils.isNotBlank(iname), ServiceItems::getIname, iname);
        return R.ok(itemsDao.selectPage(new Page<>(page, size),queryWrapper));
    }
}




